/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package be.hogent.iii.project.client.gui.gameroom;

import java.awt.Dimension;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author jef donders
 */
public class LijstPanel extends JPanel implements ListSelectionListener {

    private GameRoomGui gameRoom;
    private JList lijst;
    private String[] inhoud;
    private String type;

    public LijstPanel() {


    }

    public LijstPanel(GameRoomGui gui, String type, Dimension size, String[] inhoud, String eigenaar) {
        this.type = type;
        this.gameRoom = gui;
        this.inhoud = inhoud;
        lijst = new JList(inhoud);
        lijst.setCellRenderer(new LijstCellRenderer(eigenaar));
        lijst.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lijst.addListSelectionListener(this);
        lijst.setBackground(new java.awt.Color(102, 0, 0));
        lijst.setFont(new java.awt.Font("Tahoma", 1, 11));
        lijst.setForeground(new java.awt.Color(204, 153, 0));

        setBackground(new java.awt.Color(0, 0, 0));
        setForeground(new java.awt.Color(255, 255, 255));
        
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        setLayout(layout);
        layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(lijst, size.width - 5, size.width - 5, size.width - 5));
        layout.setVerticalGroup(layout.createSequentialGroup().addComponent(lijst, size.height - 100, size.height - 50, size.height - 50));
    }

    public void valueChanged(ListSelectionEvent e) {
        if (!e.getValueIsAdjusting()) {
            if (type.equalsIgnoreCase("Spelers")) {
                gameRoom.setInhoudInfoPanelSpeler(inhoud[lijst.getSelectedIndex()]);
            } else if (type.equalsIgnoreCase("Games")) {
                //System.out.println("index: " + lijst.getSelectedIndex());
                gameRoom.setInhoudInfoPanelGame(lijst.getSelectedIndex());
            }
        }
    }
}
